<?php
/**
 * Celebrio FileSystem module
 *
 * @copyright  Copyright (c) 2011 Celebrio Software
 * @package    Celebrio
 * @subpackage FileSystem
 */
namespace Celebrio\FileSystem;

use Nette\Object;
use Nette\Security\Permission;

use Celebrio\FileSystem\FileAclModel;

/**
 * HANDLER
 *
 * @author pavel, honza
 */
class FileAcl extends Permission {

    public function __construct() {
        $model = new FileAclModel();

        foreach($model->getRoles() as $role) {
            $this->addRole($role->name, $role->parent_name);
        }
        foreach($model->getResources() as $resource) {
            $this->addResource($resource->url . $resource->name_file);
        }

        foreach($model->getRules() as $rule){
            $this->{$rule->allowed  ? 'allow' : 'deny'}($rule->role, $rule->url . $rule->name, $rule->privilege);
        }
    }
}


